package cn.dy.workatten;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.dy.base.framework.esb.def.IModule;
import cn.dy.base.framework.esb.def.IModuleContext;
import cn.dy.workatten.imp.DutyAllowanceServiceImpl;
import cn.dy.workatten.imp.ScheduleCfgServiceImpl;
import cn.dy.workatten.imp.WorkAttenServiceImpl;
import cn.dy.workatten.service.DutyAllowanceService;
import cn.dy.workatten.service.ScheduleCfgService;
import cn.dy.workatten.service.WorkAttenService;

public class WorkAttenModuleImp implements IModule {

	public static IModuleContext context;
	protected static Logger logger = LoggerFactory.getLogger(WorkAttenModuleImp.class);
	protected static HashMap<String, Class<?>> instanceMap;

	public WorkAttenModuleImp() {
		init();
	}

	private void init() {
		instanceMap = new HashMap();

		instanceMap.put(ScheduleCfgService.class.getName(), ScheduleCfgServiceImpl.class);
		instanceMap.put(WorkAttenService.class.getName(), WorkAttenServiceImpl.class);
		instanceMap.put(DutyAllowanceService.class.getName(), DutyAllowanceServiceImpl.class);
	}

	public Object createService(Class interfaceClass) {
		try {
			Class cl = (Class) instanceMap.get(interfaceClass.getName());
			return cl.newInstance();
		} catch (Exception e) {
			logger.warn("", e);
		}
		return null;
	}

	public void loadModule(IModuleContext arg0) {
		context = arg0;
		logger.warn("模块[" + context.getModuleName() + "]启动");
	}

	public boolean serviceAlive(String arg0) {
		return true;
	}

	public void uninstallModule() {
		logger.warn("模块[" + context.getModuleName() + "]卸载");
	}

}
